//
//  LoginDataMange.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/11.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "LoginDataMange.h"
#import "API.h"
#import "JSONKit.h"
#import "StringTool.h"

#import "PremisesModel.h"


@implementation LoginDataMange

#pragma mark 登陆
-(ResulteMod *)loginWithAccount:(NSString *)account WithPassword:(NSString *)password;
{
    NSString *url = [NSString stringWithFormat:@"%@",[API urlMake:login]];
    
    NSString *pwd = [NSString md5:password];
    NSDictionary *dict = @{@"account":account,@"password":pwd};
    
   ResulteMod *mod = [Connect doPostOutCaCheWithUrl:url withParamDic:dict];
  
    
    mod.resultCode = [NSString stringWithFormat:@"%@",[mod.resultDic objectForKey:@"code"]];
   
    if (![mod.resultCode isEqualToString:@"20003"]) {
        mod.resltState = ResultFail;
        
        mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        return mod;
    }
    mod.dataMod = mod.resultDic[@"info"];
    return mod;
    
}

#pragma mark 获取短信验证码
-(ResulteMod *)captchaWithMobile:(NSString *)mobile;

{
    NSString *url = [NSString stringWithFormat:@"%@%@",[API urlMake:captcha],mobile];
    ResulteMod *mod = [Connect doGetWithOutCaChe:url];
    NSDictionary *reDic = [mod.resultData objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    mod.resultCode = [NSString stringWithFormat:@"%@",reDic[@"code"]];
    mod.resultTip = reDic[@"message"];
    
    if (![mod.resultCode isEqualToString:@"1001"]) {
        mod.resltState = ResultFail;
            mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
       
    }

    return mod;
}

#pragma mark 激活用户
-(ResulteMod *)activitymobileWithMobile:(NSString *)mobile WithCaptcha:(NSString *)captchaStr WithConsumerId:(NSInteger)consumerId;
{
    NSString *url = [NSString stringWithFormat:@"%@%@/%zd/%@",[API urlMake:activitymobile],mobile,consumerId,captchaStr];
    ResulteMod *mod = [Connect doGetWithOutCaChe:url];
    NSDictionary *reDic = [mod.resultData objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
     mod.resultCode = [NSString stringWithFormat:@"%@",reDic[@"code"]];
     mod.resultTip = reDic[@"message"];
    
    if (![mod.resultCode isEqualToString:@"1001"]) {
        
        if ([mod.resultCode isEqualToString:@"30002"]) {
            mod.resultTip = @"验证码错误";
        }else
        {
            mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        }

        
    }

    
    return mod;
}


#pragma mark 忘记密码  mobile 手机号，captcha 验证码，passWord 密码，rePassWord 重复密码
-(ResulteMod *)resetpWithMobile:(NSString *)mobile WithCaptcha:(NSString *)captchaStr WithPassword:(NSString *)passWord WithRePassWord:(NSString *)rePassWord
{
    NSString *url = [NSString stringWithFormat:@"%@",[API urlMake:resetpwd]];
    NSString *rePassWordStr = [NSString md5:rePassWord];
      NSDictionary *dict = @{@"mobile":mobile,@"captcha":captchaStr,@"passWord":rePassWordStr,@"rePassWord":rePassWordStr};
    
     ResulteMod *mod = [Connect doPostOutCaCheWithUrl:url withParamDic:dict];
    
   
    mod.resultCode = [NSString stringWithFormat:@"%@",mod.resultDic[@"code"]];
    mod.resultTip = mod.resultDic[@"message"];
    if (![mod.resultCode isEqualToString:@"20003"]) {
        mod.resltState = ResultFail;
        if ([mod.resultCode isEqualToString:@"30002"]) {
            mod.resultTip = @"验证码错误";
        }else
        {
            mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        }

    
    }
    
    return mod;
}

#pragma mark 经纪人注册
-(ResulteMod *)brokerregisterWithBrokerRegistModel:(BrokerRegistModel *)model;
{
    NSString *url = [API urlMake:brokerregister];;
    NSString *pwd = [NSString md5:model.password];
    NSDictionary *dict = @{@"name":model.name,@"mobile":model.mobile,@"captcha":model.captcha1,@"password":pwd,@"repassword":pwd,@"companyCode":model.companyCode,@"storeCode":model.storeCode};
    
    ResulteMod *mod = [Connect doPostWithOutCaCheWithUrl:url withFormdata:dict];
    
    if (![mod.resultCode isEqualToString:@"20003"]) {
        
        mod.resltState = ResultFail;
        
        if ([mod.resultCode isEqualToString:@"30002"]) {
            mod.resultTip = @"验证码错误";
        }else
        {
            mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        }

        
    }
    
    return mod;
}

#pragma mark 经纪人注册获取验证码
-(ResulteMod *)brokerregistercaptcha:(NSString *)mobile;
{
    NSString *url = [NSString stringWithFormat:@"%@%@",[API urlMake:brokerregistercaptcha1],mobile];
    ResulteMod *mod = [Connect doGetWithOutCaChe:url];
    NSDictionary *reDic = [mod.resultData objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    mod.resultCode = [NSString stringWithFormat:@"%@",reDic[@"code"]];
    mod.resultTip = reDic[@"message"];
    
    if (![mod.resultCode isEqualToString:@"1001"]) {
        mod.resltState = ResultFail;
        mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        
    }
    
    return mod;

}

@end
